<template>
  <div class="UserTaskStats">
    <div class="top">
      <!-- 工单统计 S -->
      <div class="order">
        <!-- 标题开始 -->
        <div class="title">
          <div class="titleInfo">
            <div class="text">工单统计</div>
          </div>
        </div>
        <!-- 标题结束 -->
        <!-- 数据展示开始 -->
        <div class="infoNum">
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.left?.total}}</div>
              <div class="text">工单总数（个）</div>
            </div>
          </div>
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.left?.completedTotal}}</div>
              <div class="text">完成工单（个）</div>
            </div>
          </div>
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.left?.cancelTotal}}</div>
              <div class="text">进行工单（个）</div>
            </div>
          </div>
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.left?.workerCount}}</div>
              <div class="text">取消工单（个）</div>
            </div>
          </div>
        </div>
        <!-- 数据展示结束 -->
      </div>
      <!-- 工单统计 N -->
      <!-- 销售统计 S -->
      <div class="sale">
        <!-- 标题开始 -->
        <div class="title">
          <div class="titleInfo">
            <div class="text">销售统计</div>
          </div>
        </div>
        <!-- 标题结束 -->
        <!-- 数据展示开始 -->
        <div class="infoNum">
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.right?.total}}</div>
              <div class="text">工单总数（个）</div>
            </div>
          </div>
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.right?.completedTotal}}</div>
              <div class="text">完成工单（个）</div>
            </div>
          </div>
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.right?.cancelTotal}}</div>
              <div class="text">进行工单（个）</div>
            </div>
          </div>
          <div class="flex">
            <div>
              <div class="num">{{ reportInfoList.right?.workerCount}}</div>
              <div class="text">取消工单（个）</div>
            </div>
          </div>
        </div>
        <!-- 数据展示结束 -->
      </div>
      <!-- 销售统计 N -->
    </div>
    <!-- 数据展示 -->
    <div class="info">
      <div class="left">
        <!-- 标题开始 -->
        <div class="title">
          <div class="titleInfo">
            <div class="text">销售数据</div>
          </div>
          <div class="more">
            <div class="sub">
              <div class="item" :class="dataSwitch === '周' ? 'active' : '' " @click="getCartData('周')">周</div>
              <div class="item" :class="dataSwitch === '月' ? 'active' : '' " @click="getCartData('月')">月</div>
              <div class="item" :class="dataSwitch === '年' ? 'active' : '' " @click="getCartData('年')">年</div>
            </div>
          </div>
        </div>
        <!-- 标题结束 -->
        <div class="table">
            <el-empty :image="empty" description="暂无数据"></el-empty>
        </div>
      </div>
      <div class="right">
        <!-- 标题开始 -->
        <div class="title">
          <div class="titleInfo">
            <div class="text">销售数据</div>
          </div>
          <div class="more">
            <el-select v-model="hoverList" placeholder="请选择" size="mini" style="width: 100px">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in regionList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </div>
        </div>
        <!-- 标题结束 -->
        <div class="switch">
          <div class="sub">
            <div class="item" :class="WeekSwitch === '运营人员' ? 'active' : '' " @click="WeekSwitch = '运营人员'">运营人员</div>
            <div class="item" :class="WeekSwitch === '运维人员' ? 'active' : '' " @click="WeekSwitch = '运维人员'">运维人员</div>
          </div>
        </div>
        <div class="table">
            <el-empty :image="empty" description="暂无数据"></el-empty>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getTaskReportInfo } from '@/api/public'
import { getRegion } from '@/api/UserAPIs'
import { getToday } from '@/utils/tool'
export default {
  data () {
    return {
      reportInfoList: {
        left: {},
        right: {}
      },
      // 周月年切换
      dataSwitch: '周',
      WeekSwitch: '运营人员',
      empty: require('@/assets/empty.png'),
      regionList: [],
      hoverList: ''
    }
  },
  created () {
    this.reportInfo(getToday().split(' ')[0] + ' 00:00:00', getToday())
    this.getRegion()
  },
  methods: {
    async reportInfo (start, end) {
      const { data } = await getTaskReportInfo({ start, end })
      this.reportInfoList.left = data[0]
      this.reportInfoList.right = data[1]
    },
    async getRegion () {
      const { data: { currentPageRecords: regionList } } = await getRegion({
        pageIndex: 1,
        pageSize: 114514
      })
      this.regionList = regionList
    }
  }
}
</script>

<style lang="scss" scoped>
.UserTaskStats {
  overflow: hidden;
}
.top {
  width: 100%;
  display: flex;
  // 工单统计
  .order {
    flex: 1;
    margin-right: 20px;
    // 设置背景图片
    background-image: url("~@/assets/User-BG-0.png"),
      url("@/assets/HomeTaskTwo.png");
    // 关闭背景图重复
    background-repeat: no-repeat;
    // 背景图定位
    background-position: calc(100% - 12px) 100%, 0 0;
    // 背景颜色
    background-color: #e9f3ff;
    // infoNum里的
    .infoNum .num {
      color: #072074;
      text-shadow: 2px 4px 7px rgb(85 132 255 / 50%);
    }
    // infoNum里的
    .infoNum .text {
      color: #91a7dc;
    }
  }
  // 销售统计
  .sale {
    flex: 1;
    // 设置背景属性
    background: #fbefe8 url("~@/assets/User-BG-1.png") no-repeat calc(100% - 12px) 100%;
    // infoNum里的
    .infoNum .num {
      color: #ff5757;
      text-shadow: 2px 4px 7px rgb(255 99 85 / 50%);
    }
    // infoNum里的
    .infoNum .text {
      color: #de9690;
    }
  }
  // 工单与销售的公共样式
  .order,
  .sale {
    height: 126px;
    border-radius: 20px;
    padding: 20px;
  }
  // 数据展示
  .infoNum {
    display: flex;
    height: 100%;
    // 让文字居中
    .flex {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .num {
      font-size: 36px;
      font-weight: 700;
    }
    .text {
      margin-top: 3px;
      font-size: 12px;
    }
  }
}
.info {
  margin-top: 20px;
  display: flex;
  .left, .right {
    height: 502px;
    padding: 20px;
    border-radius: 20px;
    background: #fff;
    box-sizing: border-box;
  }
  .left {
    flex: 20;
    margin-right: 20px;
    .table, .el-empty {
      height: calc(100% - 20px);
    }
  }
  .right {
    flex: 6;
    .table, .el-empty {
      height: calc(100% - 42px);
    }
    .switch {
      display: flex;
      justify-content: center;
      margin-top: 10px;
    }
  }
}
.data {
  height: 352px;
  border-radius: 20px;
  padding: 20px;
  box-sizing: border-box; // 开启内减
  background: #fff;
  .echarts {
    display: flex;
    height: 100%;
    .item {
      flex: 50%;
    }
  }
  .el-empty {
    width: 50%;
  }
}
// 公共标题
  .title {
    display: flex;
    justify-content: space-between;
    // 标题部分
    .titleInfo {
      display: flex;
      align-items: center;
      .text {
        font-size: 16px;
        font-weight: 700;
        color: #333;
      }
      .time {
        font-size: 12px;
        margin-left: 10px;
        color: #999;
      }
    }
    // 更多部分
    .more {
      i {
        zoom: 0.67; // 自己造的 icon 需要缩放
        color: #5f84ff !important;
        border: 2px solid #5f84ff;
        border-radius: 20px;
        padding: 2px;
        cursor: pointer;
      }
    }
  }
.sub {
  padding: 0 4px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 14px;
  border-radius: 10px;
  background: #f8fafd;
  color: #9ca3b4;
  .item {
    height: 25px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    &.active {
      box-shadow: 0 0 4px 0 rgb(0 0 0 / 11%);
      border-radius: 7px;
      background: #fff;
      color: #000;
      font-weight: 700;
    }
  }
}
</style>
